package com.gxan.dao.impl;

import com.gxan.common.Constants;
import com.gxan.dao.HouseDao;
import com.gxan.pojo.House;
import com.gxan.utils.db.JdbcUtils;
import java.sql.SQLException;
import java.util.List;

public class HouseDaoImpl extends JdbcUtils implements HouseDao {
//    @Override
//    public Integer countHouse() throws SQLException {
//        String sql = "select count(*) from house where status!=?";
//        Object[] params = {Constants.STATUS_DEL};
//        return super.findAllForInt(sql,params);
//    }

    @Override
    public Integer countHouse(String... huzhu_name) throws SQLException {
        String sql = null;
        Object[] params = null;
        if(huzhu_name.length != 0){
            sql = "select count(*) from house where status!=? and huzhu_name=?";
            params = new Object[]{Constants.STATUS_DEL, huzhu_name};
        }else{
            sql = "select count(*) from house where status!=?";
            params = new Object[]{Constants.STATUS_DEL};
        }
        return super.findAllForInt(sql,params);
    }



    @Override
    public List<House> queryHouseList(Integer param01, Integer param02, String... huzhu_name) throws SQLException {
        String sql;
        Object[] params;
        if(huzhu_name.length == 0 ){
            sql = "select * from house where status!=? limit ?,?";
            params = new Object[]{Constants.STATUS_DEL, param01, param02};
        }else{
            sql = "select * from house where status!=? and huzhu_name=? limit ?,?";
            params = new Object[]{Constants.STATUS_DEL, huzhu_name, param01, param02};
        }
        return super.queryListEntity(House.class,sql,params);
    }

    @Override
    public int delHouseById(String id) throws SQLException {
        String sql = "update house set status=? where id=?";
        Object[] params = {Constants.STATUS_DEL,id};
        return super.executeUpdate(sql,params);
    }

    @Override
    public int updateHouse(House house) throws SQLException {
        String sql = "update house set community_id=?,dong_id=?,house_name=?,huzhu_name=?,huzhu_tel=?,house_depart=? where id=?";
        Object[] params = {house.getCommunity_id(),house.getDong_id(),house.getHouse_name(),house.getHuzhu_name(),house.getHuzhu_tel(),house.getHouse_depart(),house.getId()};
        return super.executeUpdate(sql,params);
    }

    @Override
    public int addHouse(House house) throws SQLException {
        String sql = "insert into house values(null,?,?,?,?,?,?,?,?,?,?,?)";
        Object[] params = {house.getCommunity_id(),house.getDong_id(),house.getHouse_num(),house.getHouse_name(), house.getHuzhu_name(),house.getHuzhu_tel(),house.getHouse_type(),house.getHouse_depart(),house.getHouse_level(),house.getJoin_time(),Constants.STATUS_OK};
        return super.executeUpdate(sql,params);
    }


}
